<?php
/* -------------------------------------------------------------------------------------
* 	fork by itDOT Media - dirk mueller
* 	http://www.itdotmedia.de
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

function startsWith($haystack, $needle) {
  return strpos($haystack, $needle) === 0;
}

function endsWith($haystack, $needle) {
  return substr($haystack, -strlen($needle)) == $needle;
}

function parseTags(&$haystack, $remove=false, $ldelim = '{', $rdelim = '}') {
  $pattern = '/'.$ldelim.'([a-z_]*)'.$rdelim.'(.*)'.$ldelim.'\\/(.*)'.$rdelim.'/U';
  $items = array();

 if (preg_match_all($pattern, $haystack, $matches)) {
    for($idx = 0; $idx < count($matches[0]); $idx++) {
      if ($matches[1][$idx] != $matches[3][$idx]) return false;
      if($remove) $haystack = str_replace($matches[0][$idx], '', $haystack);
      if (!isset($items[$matches[1][$idx]])) $items[$matches[1][$idx]] = array(); 
      $items[$matches[1][$idx]][] =  $matches[2][$idx];
    }
  }
  
  return $items;
}